#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    qServer = new QTcpServer(this);
    qServer->listen(QHostAddress::Any , 8989);
    connect(qServer,SIGNAL(newConnection()), this , SLOT(newConnectionSlot()));
}

void MainWindow::newConnectionSlot()
{
    qDebug()<<"连接成功"<<endl;
    QTcpSocket *pSocket = qServer->nextPendingConnection();
    char buf[128] = "hhhhhhhhhhhh";
    char buf1[128];
    pSocket->write(buf,sizeof(buf));
    pSocket->read(buf1,sizeof(buf1));
    qDebug()<<buf1<<endl;
    pSocket->close();
}

MainWindow::~MainWindow()
{
    delete ui;
}

